package com.cp.yn.activity

import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import com.cp.yn.UserManager
import com.cp.yn.databinding.ActivityWelcomeBinding
import com.cp.yn.manager.RouterManager
import com.didi.drouter.annotation.Router
import com.common.base.base.BaseActivity
import com.common.base.manager.PermissionManager
import com.common.base.tools.arouter.startRouter
import com.common.base.tools.utils.JsonUtils
import com.common.base.tools.utils.logger

@Router(path = RouterManager.Path.APP_Welcome)
class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
    override fun viewBinding(): ActivityWelcomeBinding {
        return ActivityWelcomeBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        logger.info("getChannel():${getChannel()}")
        enter()
    }

    private fun getChannel():String{
        try {
            return  packageManager.getApplicationInfo(packageName,PackageManager.GET_META_DATA).metaData.getString("UMENG_CHANNEL")?:"unknown"
        } catch (e:PackageManager.NameNotFoundException ) {
            e.printStackTrace();
        }
        return "unknown"

    }

    private fun permissionRequest() {
        val permissionList: List<String> = listOf(
            Manifest.permission.READ_MEDIA_IMAGES,
            Manifest.permission.READ_MEDIA_VIDEO,
            Manifest.permission.READ_MEDIA_AUDIO,
        )
        PermissionManager.reqeustPermission(this,permissionList,{

        },{list,isNode->
            logger.info("不同意的权限有" + JsonUtils.toJson(list))
            enter()
        },)

    }

    private fun enter() {
        if (UserManager.isLogin()) {
            startRouter(RouterManager.Path.APP_Main)
            finish()
        } else {
            startRouter(RouterManager.Path.APP_Login)
            finish()
        }
    }
}